{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import importlib as ilib\n",
    "import logging\n",
    "import plotly.offline as plo\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import omega_ui.backtest as ob\n",
    "import omega_ui.tearsheet as ots\n",
    "import omega_ui.tests.test_backtest as ottb\n",
    "\n",
    "plo.init_notebook_mode(connected=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Disable logging output\n",
    "log = logging.getLogger()\n",
    "log.setLevel(logging.WARNING)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Backtest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#ilib.reload(ort)\n",
    "start = time.time()\n",
    "btm = ottb.ExampleBacktest()\n",
    "# Parameters\n",
    "symbols = ['TestData']\n",
    "cash = 100000.0\n",
    "# Strategy\n",
    "strategy = ottb.StatsTest\n",
    "pnl, results = btm.run(symbols, cash, strategy)\n",
    "print('Total Profit: {:,.2f}'.format(pnl))\n",
    "print('Backtest - Execution time: {:.0f} seconds!'.format(time.time() - start))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Tearsheet & Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ilib.reload(ots)\n",
    "ts = ots.create_tearsheet(results, symbols)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plo.iplot(ts['fig'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ts['statistics']"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3.0
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}